#include <stdio.h>
int main()
{
 int i,j,n;
 double det;
 double det2(double,double,double,double);
 double det3(double,double,double,double,double,double,double,double,double);
 printf("Please enter the order of matrix you want caculate:(2or3)");
 scanf("%d",&n);
 switch(n)
{
 case(2):printf("Now please enter 4 numbers.\n");
         double a[2][2];
         for(i=0;i<2;i++)
         for(j=0;j<2;j++)
         scanf("%lf",&a[i][j]);
         det=det2(a[0][0],a[0][1],a[1][0],a[1][1]);
         printf("The determinant of the matrix is %lf.",det);
         break;
 case(3):printf("Now please enter 9 numbers.\n");
         double b[3][3];
         for(i=0;i<3;i++)
         for(j=0;j<3;j++)
         scanf("%lf",&b[i][j]);
         det=det3(b[0][0], b[0][1],b[0][2], b[1][0], b[1][1],b[1][2],b[2][0],b[2][1],b[2][2]);
         printf("The determinant of the matrix is %lf.",det);
         break;
}
 return 0;
}
double det2(double a00,double a01,double a10,double a11)
{
 double det;
 det=a00*a11-a01*a10;
 return det;
}
double det3(double a00,double a01,double a02,double a10,double a11,double a12,double a20,double a21,double a22)
{
 double det;
 double det2(double,double,double,double);
 det=a00*det2(a11,a12,a21,a22)-a10*det2(a01,a02,a21,a22)+a20*det2(a01,a02,a11,a12);
 return det;
}
